<?php
namespace app\admin\validate;
use think\Validate;

/**
 * 每日数据目标金额信息验证器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/11/21
 * Time: 14:46
 */
class WrDataTargetMoney extends Validate{

    protected $rule = [
        'year'               => 'require|date|checkYear',
        'department'         => 'require',
        'month_target_money' => 'require'
    ];

    protected $message = [
        'year.require'               => '年份必须填写',
        'year.date'                  => '年份填写错误',
        'year.checkYear'             => '年份大于或等于当前年份',
        'department.require'         => '部门必须填写',
        'month_target_money.require' => '金额必须填写'
    ];

    protected function checkYear($value){
        $year = date('Y');
        return $year > $value ? false : true;
    }

    protected $scene = [
        'add'  => ['year','department','month_target_money'],
        'edit' => ['year','department','month_target_money']
    ];
}